use crate::dto;
use crate::dto::core::endpoint::EndpointType;
use crate::dto::ipv4::Ipv4;
use crate::dto::ipv6::Ipv6;
use serde::{Deserialize, Serialize};
use validator::Validate;
use wanmesh_common::util::deserialize_some;
use wanmesh_common::validator::validate_string_is_not_empty;

#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
pub struct AddParams {
    #[validate(custom(function = "validate_string_is_not_empty"))]
    pub node_id: String,
    pub endpoint_type: EndpointType,
    #[validate(custom(function = "validate_string_is_not_empty"))]
    pub name: String,
    #[serde(default)]
    pub description: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ipv4: Option<Ipv4>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ipv6: Option<Ipv6>,
}


#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AddResponseData {
    pub endpoint_id: String,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Default, Eq, PartialEq)]
pub struct UpdateParams {
    pub name: Option<String>,
    pub description: Option<String>,
    #[serde(default, deserialize_with = "deserialize_some")]
    pub ipv4: Option<Option<dto::ipv4::UpdateParams>>,
    #[serde(default, deserialize_with = "deserialize_some")]
    pub ipv6: Option<Option<dto::ipv6::UpdateParams>>,
}

#[derive(Serialize, Deserialize, Validate, Default, Debug, Clone, Eq, PartialEq)]
pub struct Filter {
    pub node_id: Option<String>,
    pub endpoint_id: Option<String>,
    pub endpoint_type: Option<EndpointType>,
    pub name: Option<String>,
}